/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Mapper;

import java.sql.*;

/**
 *
 * @author Quang Thao
 */
public class OtherMapper {
    DBMapper map;
    
    public OtherMapper() throws SQLException
    {
        map = new DBMapper();
    }
    
    public Bean.OtherBean GetInfo(String id) throws Exception
    {
        ResultSet rs = map.ExecuteQuery("Select * From Other Where ID='" + id + "'");
        Bean.OtherBean other = new Bean.OtherBean();
        if (rs != null && rs.next())
        {
            other.setID(id);
            other.setTitle(rs.getString(2));
            other.setContent(rs.getString(3));
        }
        return other;
    }
    
    public int Update(Bean.OtherBean other) throws Exception
    {
        int kq = map.ExecuteNonQuery("Update Other Set Title='"
                + other.getTitle() + "',Contents='" + other.getContent()
                + "' Where ID='" + other.getID() + "'");
        if (kq == 0)
        {
            kq = map.ExecuteNonQuery("Insert Into Other Values('" 
                    + other.getID() + "','" + other.getTitle()
                    + "','" + other.getContent() + "')");
        }
        return kq;
    }
}
